

import NewsInfo from '../pages/viewmodel/NewsInfo';
import axios from '@ohos/axios'
class NewsModelAxios{

  baseUrl:string = 'http://api.webxd.top'
  pageNumber:number = 0
  reqToken:string = 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MDU1MDA2ODMsInVzZXJfbmFtZSI6ImZmZGQiLCJ1c2VyX2lkIjoxMH0.ZGGiosAG411D0QjjaIe52xtvkAxkmUyOkr772j7bJ3jd_7zpJnhLFBaB792Chal6DW2nLtDLXVizVtc0VbZ_zA'
  getNewsList(): Promise<NewsInfo[]> {
    console.log('进入了getNewsList()')
    return new Promise((resolve,reject)=>{
      console.log('进入了getNewsList()发送请求')
      // 2、发送请求
      axios.get(
        `${this.baseUrl}/news_info?page=${this.pageNumber}&rows=50`,
        {
          headers:{
            'Authorization':this.reqToken   //请求头参数
          }
        }
      ).then(resp=>{
        console.log(''+resp.status)
        if (resp.status === 200){
          // 告知查询成功
          console.log('查询成功,axios')
          // console.log(JSON.stringify(resp.data.data[1]))
          resolve(resp.data.data)
        }else{
          reject('查询失败')
        }

      }).catch(
        error=>{
          console.log('进入了getNewsList()catch')
          // console.log('请求出错，error:',JSON.stringify(error))
          reject('查询失败')
        }
      )
        .finally(
          ()=>{
            console.log('进入了getNewsList()finally')
          }
        )
    }
    )




  }
}


const newsModelAxios = new  NewsModelAxios();
export default  newsModelAxios as NewsModelAxios;